package com.lbmb.mdps.workbench.service.impl;

import com.lbmb.mdps.commons.domain.SupplierVo;
import com.lbmb.mdps.commons.domain.WarehouseReceive;
import com.lbmb.mdps.commons.domain.WarehouseVo;
import com.lbmb.mdps.commons.exception.WarehouseException;
import com.lbmb.mdps.workbench.dao.WarehouseDao;
import com.lbmb.mdps.workbench.domain.Supplier;
import com.lbmb.mdps.workbench.domain.Warehouse;
import com.lbmb.mdps.workbench.service.WarehouseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 林文塨
 * @date 2022-05-30 23:12
 * description
 */
@Service("warehouseService")
public class WarehouseServiceImpl implements WarehouseService {

    @Resource
    private WarehouseDao warehouseDao;

    @Override
    public List<Warehouse> warehousePageList(WarehouseReceive warehouseReceive) throws WarehouseException {
        /*
         * 分页获取仓库表功能
         * @author 林文塨
         * @date 2022/5/30 10:24
         * @param [employeeReceive]
         * @return java.util.List<com.lbmb.mdps.settings.domain.Employee>
         */
        List<Warehouse> warehouseList = warehouseDao.warehousePageList(warehouseReceive);

        if (warehouseList == null) {
            throw new WarehouseException("分页获取仓库列表失败！");
        }

        return warehouseList;
    }

    @Override
    public Integer getWarehouseTotal(WarehouseReceive warehouseReceive) throws WarehouseException {
        /*
         * 获取仓库分页总条数功能
         * @author 林文塨
         * @date 2022/5/30 10:42
         * @param [employeeReceive]
         * @return java.lang.Integer
         */
        Integer total = warehouseDao.getWarehouseTotal(warehouseReceive);

        if (total < 0) {
            throw new WarehouseException("获取仓库分页总条数失败！");
        }

        return total;
    }

    @Override
    public void addWarehouse(Warehouse warehouse) throws WarehouseException {
        /*
         * 添加仓库
         * @author 林文塨
         * @date 2022/5/30 13:06
         * @param [employee]
         * @return void
         */
        int result = warehouseDao.addWarehouse(warehouse);

        if (result != 1) {
            throw new WarehouseException("添加仓库失败！");
        }
    }

    @Override
    public void editWarehouse(Warehouse warehouse) throws WarehouseException {
        /*
         * 修改仓库
         * @author 林文塨
         * @date 2022/5/30 13:06
         * @param [employee]
         * @return void
         */
        int result = warehouseDao.editWarehouse(warehouse);

        if (result != 1) {
            throw new WarehouseException("修改仓库失败！");
        }
    }

    @Override
    public void deleteWarehouse(String[] deleteWarehouseIds) throws WarehouseException {
        /*
         * 删除仓库
         * @author 林文塨
         * @date 2022/5/30 16:32
         * @param [deleteEmployeeIds]
         * @return void
         */
        int result = warehouseDao.deleteWarehouse(deleteWarehouseIds);

        if (result <= 0) {
            throw new WarehouseException("删除仓库失败");
        }
    }

    @Override
    public List<WarehouseVo> getAllWarehouse() {
        /*
         * 获得全部仓库
         * @author 林文塨
         * @date 2022/6/1 1:30
         * @param []
         * @return java.util.List<com.lbmb.mdps.commons.domain.WarehouseVo>
         */
        List<Warehouse> warehouseList = warehouseDao.getAllWarehouse();

        List<WarehouseVo> warehouseVoList = new ArrayList<>();

        for (Warehouse warehouse : warehouseList) {
            WarehouseVo warehouseVo = new WarehouseVo();
            warehouseVo.setLabel(warehouse.getName());
            warehouseVo.setValue(warehouse.getId());

            warehouseVoList.add(warehouseVo);
        }

        return warehouseVoList;
    }
}
